/** @odoo-module **/
class cellEditor {
    init(params) {
        this.value = params.value;
        this.charPress = params.charPress;
        // this.currentValue = params.value;
        let el = document.createElement('div');
        let _html = '';
        _html += `<input type="number" class="form-control" min="0" max="100" placeholder="0-100" value="${this.value}" style="width: 100%;max-width: 100px"/>`;
        el.innerHTML = _html;
        this.el = el;
        this.inputEl = this.el.querySelector('input');
        this.inputEl.addEventListener('input', (event) => {
            this.value = event.target.value;
        });
    }

    getGui() {
        return this.el;
    }

    getValue() {
        // this simple editor doubles any value entered into the input
        return Number(this.value);
    }

    // Gets called once before editing starts, to give editor a chance to
    // cancel the editing before it even starts.
    isCancelBeforeStart() {
        return false;
    }

    // Gets called once when editing is finished (eg if Enter is pressed).
    // If you return true, then the result of the edit will be ignored.
    isCancelAfterEnd() {
        // our editor will reject any value greater than 1000
        return this.value > 100 || this.value < 0 ;
    }

    afterGuiAttached(){
        this.inputEl.value = '';
        this.inputEl.focus();
        let _str = this.charPress;
        if(_str){
            this.value = _str;
        }
        this.inputEl.value = this.value;

    }
    isPopup(){
        return true
    }
}

export default cellEditor
